package lib

func init() {
	Probs = append(Probs, Problem{
		Num:         3,
		Discription: "无重复最长字串",
		Level:       2,
		Labels: map[string]int{
			"滑动窗口": 1,
			"哈希表":  1,
		},
	})
}

func LengthOfLongestSubstring(s string) int {
	left := 0
	right := 1
	maxLen := 0
	chMap := make(map[byte]bool)
	for right <= len(s) {
		ch := s[right-1]
		for chMap[ch] {
			delete(chMap, s[left])
			left++
		}

		chMap[ch] = true
		maxLen = max(maxLen, right-left)
		right++
	}

	return maxLen
}
